// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.

const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('electronAPI', {
  minWin: () => {
    ipcRenderer.send('min-win')
  },
  maxWin: () => {
    ipcRenderer.send('max-win')
  },
  restoreWin: () => {
    ipcRenderer.send('restore-win')
  },
  closeWin: () => {
    ipcRenderer.send('close-win')
  }
})
window.addEventListener('DOMContentLoaded', () => {

  document.getElementById('closeWindow').addEventListener('click', () => { 
	// alert(ipcRenderer.getCurrentWindow())
    console.log("btnClose click")
    ipcRenderer.send('close-win')
  })

  document.getElementById('maxWindow').addEventListener('click', () => {
    ipcRenderer.send('max-win')
  })

  document.getElementById('minWindow').addEventListener('click', () => {

    ipcRenderer.send('min-win')
  })

  document.getElementById('unMaxWindow').addEventListener('click', () => {
    ipcRenderer.send('window-un-max');
  })
  document.getElementById('winSettings').addEventListener('click', () => {
    ipcRenderer.send('window-settings');
  })


  function processActions(isMaximized) {
    console.log("isMaximized:",isMaximized)
    // if (isMaximized) {
    //   document.getElementById('unMaxWindow').style.display = 'inline-flex'
    //   document.getElementById('maxWindow').style.display = 'none'
    // } else {
    //   document.getElementById('maxWindow').style.display = 'inline-flex'
    //   document.getElementById('unMaxWindow').style.display = 'none'
    // }
  }

  ipcRenderer.on('win-unmaximize', function () {
    processActions(false)
  })

  ipcRenderer.on('win-maximize', function () {
    processActions(true)
  })

  ipcRenderer.on('win-ready', function (e, isMaximized) {
    processActions(isMaximized)
  })

})
